﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace HotelManagement
{
    public partial class RoomSearchFRM : Form
    {
        SqlConnection Cnn = new SqlConnection(Globals.DBConnection());
        DataSet ds = new DataSet();
        SqlDataAdapter da;

        public string RoomNumber;
        public int RoomID;
        public string RoomPrice;

        public RoomSearchFRM()
        {
            InitializeComponent();
        }

        private void RoomSearchFRM_Load(object sender, EventArgs e)
        {
            da = new SqlDataAdapter("select rm_id as [ردیف], rm_number as [شماره اتاق],rm_floor as [طبقه],rt_capacity as [ظرفیت],rt_type_name as [نوع اتاق] ,rp_price as [هزینه] from Room,Room_Type,Room_Price where rm_type=rt_id AND rp_rt_id=rt_id", Cnn);
            da.Fill(ds);
            dGViewRoom.DataSource = ds.Tables[0];
        }

        private void RoomTypeTxt_TextChanged(object sender, EventArgs e)
        {
            da = new SqlDataAdapter("select rm_id as [ردیف], rm_number as [شماره اتاق],rm_floor as [طبقه],rt_capacity as [ظرفیت],rt_type_name as [نوع اتاق] ,rp_price as [هزینه] from Room,Room_Type,Room_Price where (rt_type_name LIKE @type_name + N'%' OR @type_name=N'') AND (rt_capacity = @capacity OR @capacity='') AND rm_type=rt_id AND rp_rt_id = rt_id", Cnn);
            da.SelectCommand.Parameters.AddWithValue("@type_name",RoomTypeTxt.Text.Trim());
            da.SelectCommand.Parameters.AddWithValue("@capacity", RoomCapacityTxt.Text.Trim());
            ds.Clear();
            da.Fill(ds);
            dGViewRoom.DataSource = ds.Tables[0];
        }

        private void dGViewRoom_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            RoomNumber = dGViewRoom.CurrentRow.Cells[1].Value.ToString();
            RoomID = (int)dGViewRoom.CurrentRow.Cells[0].Value;
            RoomPrice = dGViewRoom.CurrentRow.Cells[5].Value.ToString();
        }
    }
}
